import path from 'path'
import { app } from 'electron'
import fs from 'fs'
import { PATH } from '../utils';
const dataRootPath=PATH.dataPath;
if(!fs.existsSync(dataRootPath)){
  if(!fs.existsSync(`D:\\ProgramData`)){
    fs.mkdirSync(`D:\\ProgramData`)
  }
  fs.mkdirSync(dataRootPath);
}
const dataPath = path.join(dataRootPath, 'data.json')

export const saveUserInfo = (userInfo) => {
  return fs.writeFileSync(
    dataPath,
    JSON.stringify(userInfo || {}),
    { encoding: "utf-8" }
  );
}

export const getUserInfo = () => {
  if (!fs.existsSync(dataPath)) return null
  return fs.readFileSync(dataPath, { encoding: "utf-8" });
}
